In [1]:
using Revealables


Run the cells below to generate buttons that will reveal HTML. The code cells are hidden by the Hide Input IPython notebook extension, which is automatically installed by the Revealables package.


In [2]:
revealable("""
#Revealables.jl
Hide and reveal text with the click of a button
""", "Click this button!", false)


Out[2]:

If you have Hide Input installed, the code cell above is hidden and you can see only the button. You can unhide the code cells above by clicking on the chevron-up icon. (If you don't have the Hide Input extension, the code wasn't hidden in the first place.)

Creating Revealables


In [3]:
h = Revealable("""
You can use two steps to create a button:
1. Create an instance of a <code>Revealable</code>, which has three fields:
   * Markdown (which can include HTML) to display [<code>ASCIIString</code>]
   * the label to use on a button [<code>ASCIIString</code>]
   * whether or not the Markdown should be displayed automatically (`false` by default) [<code>Bool</code>]
2. run the <code>revealable</code> function to create the button.
""", "This is the button's label", false)

revealable(h)


Out[3]:

In [4]:
revealable("""
You can also just run the <code>revealable</code> function 
and pass in the same arguments as if you were instantiating 
the <code>Revealable</code> type. The same defaults and 
options apply.
""", "Another Button!", false)


Out[4]:

In [5]:
variable = "This is an interpolated string!"

formatted = "<font color=blue>This string includes HTML.</font>"

revealable("""
You can include variables in your Revealable by using normal
Julia string interpolation. $variable $formatted You have to escape the characters
\", \$, \\, \\\*, and \# as shown in the code.
""", "Interpolate Variables", false)


Out[5]:

Default Values

Since Revealables are set not to show initially, you can omit the last argument. If you do not want to set your own label for the button, you can also omit the second string.


In [6]:
revealable("""There is only an <font color="purple">ASCIIString argument</font> 
passed to this function. The string will be displayed as Markdown, 
which can handle many HTML tags.""")


Out[6]:

In [7]:
revealable("""In addition to including HTML and Markdown, you can
format your text through CSS classes. That will require you to
define new classes in your custom.css file.""")


Out[7]:

Encoding and Decoding Revealables


In [8]:
text = Revealable("""You can encode content using a Caesar cipher
so students can't easily see answers until you give them the password.

There are two ways to encode the Revealable:
* `encode!` (destructive)
* `encode` (returns a new Revealable with the content of the old Revealable encoded)

Likewise, there are two ways to decode the encoded Revealable:
* `decode!` (destructive)
* `decode` (returns a new Revealable with the content of the old Revealable decoded)

You cannot double-encode or double-decode a Revealable. If a Revealable has been encoded, 
you cannot encode it again unless it is decoded first.""")
revealable(text)


Out[8]:

In [9]:
encode!(text, "password")
revealable(text)


Out[9]:

Xnt bzm dmbncd bnmsdms trhmf z Bzdrzq bhogdq rn rstcdmsr bzm's dzrhkx rdd zmrvdqr tmshk xnt fhud sgdl sgd ozrrvnqc.

Sgdqd zqd svn vzxr sn dmbncd sgd Qdudzkzakd:

  • dmbncd! (cdrsqtbshud)
  • dmbncd (qdstqmr z mdv Qdudzkzakd vhsg sgd bnmsdms ne sgd nkc Qdudzkzakd dmbncdc)

Khjdvhrd, sgdqd zqd svn vzxr sn cdbncd sgd dmbncdc Qdudzkzakd:

  • cdbncd! (cdrsqtbshud)
  • cdbncd (qdstqmr z mdv Qdudzkzakd vhsg sgd bnmsdms ne sgd nkc Qdudzkzakd cdbncdc)

Xnt bzmmns cntakd-dmbncd nq cntakd-cdbncd z Qdudzkzakd. He z Qdudzkzakd gzr addm dmbncdc, xnt bzmmns dmbncd hs zfzhm tmkdrr hs hr cdbncdc ehqrs.


In [10]:
decode!(text, "password")
revealable(text)


Out[10]:

Other Uses

With Interact's widgets:


In [11]:
slidercontent = [
    Revealable("""<font color="#990000">Step 1: Make an array of Revealables with `show` set to `true`</font>""", "", true),
    Revealable("""<font color="#009900">Step 2: using `Interactive.@manipulate`, create a slider (or other widget)</font>""", "", true),
    Revealable("""<font color="#000099">Step 3: Display the correct Revealable by using the widget. The Revealable will use the richest display available.</font>""", "", true),
    Revealable("""I use this most often for stepping through a series of images with explanations.""", "", true)]

using Interact
@manipulate for s = slider(1:4, value=1)
    slidercontent[s]
end


Out[11]:

Step 1: Make an array of Revealables with `show` set to `true`

Limitations

If put multiple buttons in one cell, only the last button will work.


In [12]:
revealable("""
    The first button won't work.
""", "Broken Button", false)

revealable("""
    The second button won't work.
""", "Another Broken Button", false)

revealable("""Only the third button works! 
If you know how to fix this, I'd love to learn.""", "Functional Button!", false)


Out[12]:

Also, the Markdown in button output can't display LaTeX.


In [13]:
revealable("""
Markdown doesn't render LaTeX: \$\\frac{3^x}{x-2}\$. Use HTML and less nice formatting instead: (3<sup>x</sup>)/(x-2).
""", "No LaTeX", false)


Out[13]:

In [ ]: